package com.smartx.app.util.libimage;

import android.graphics.drawable.Drawable;

import com.bumptech.glide.request.target.SimpleTarget;

import java.io.File;

/**
 * @author: tangjie
 * @date: 2017/3/30 13:45
 * @Description:
 */

public abstract class ImageDownloadTarget extends SimpleTarget<File> implements
        GlideDownloadProgress.ProgressListener {
    private final String mUrl;

    protected ImageDownloadTarget(String url) {
        mUrl = url;
    }

    @Override
    public void onLoadCleared(Drawable placeholder) {
        super.onLoadCleared(placeholder);
        GlideDownloadProgress.forget(mUrl);
    }

    @Override
    public void onLoadStarted(Drawable placeholder) {
        super.onLoadStarted(placeholder);
        GlideDownloadProgress.onStart(mUrl, this);
    }

    @Override
    public void onLoadFailed(Exception e, Drawable errorDrawable) {
        super.onLoadFailed(e, errorDrawable);
        GlideDownloadProgress.onFail(mUrl);
    }

}
